Thread: does s[i] = s[j]?

  1. #1
    Registered User xion's Avatar
    Join Date
    Jul 2003
    Posts
    63

    does s[i] = s[j]?

    having trouble with array elements.

    Code:
    i = 0;
    j = 0;
    
    s[i] = 'a';
    s[j] = 'b';
    can these above statements exist? can s[i] be different from s[j] even though they stand in the same array element 0? im working on a k&r exercise and was a little confused.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    No. That code is the same as this.

    Code:
    s[0]='a';
    s[0]='b';
    edit: well, they can exist, but not in the way I think you meant the question.
    Last edited by confuted; 08-13-2003 at 11:32 PM.
    Away.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Syntactically speaking, those statements can exist.
    Theoretically speaking, they can exist.
    Practically speaking, it's questionable.

  4. #4
    Registered User xion's Avatar
    Join Date
    Jul 2003
    Posts
    63
    Originally posted by confuted
    [B]No. That code is the same as this.

    Code:
    s[0]='a';
    s[0]='b';

    so basically the 2nd statement will overwrite the first.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    32
    so basically the 2nd statement will overwrite the first.
    Yep. Nothing special going on here.
    Beware the fury of a patient man.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The C programming language exercise
    By refuser in forum C Programming
    Replies: 10
    Last Post: 11-20-2008, 03:57 PM
  2. I need help with looping
    By ben2000 in forum C Programming
    Replies: 3
    Last Post: 07-30-2007, 04:47 PM
  3. a question about file output
    By wang8442 in forum C Programming
    Replies: 3
    Last Post: 12-26-2004, 03:18 AM
  4. expand(int s[]) 3-3 knr
    By olbas in forum C Programming
    Replies: 2
    Last Post: 04-06-2004, 11:01 AM
  5. Arrays..and arguments
    By fanaonc in forum C Programming
    Replies: 2
    Last Post: 10-16-2001, 04:58 PM